﻿using UnityEngine;
using System.Collections;

public class FangHuZhao : MonoBehaviour {

	Player obj;
	Transform m_Transform;
	//防护罩血量
	public static int fanghuzhao_Life =5;
	void Start () {
		m_Transform = this.transform;
		obj = GameObject.FindGameObjectWithTag("Player").gameObject.GetComponent<Player>();
	}

	void Update () {
		if(obj!=null)
		{
		  m_Transform.position = obj.transform.position;
		}else{
			Destroy(this.gameObject);
		}

		if(fanghuzhao_Life<=0)
		{
            Player.player_Life_bool = true;
			Destroy(this.gameObject);
        } Debug.Log(fanghuzhao_Life);
	}

	void OnTriggerEnter2D(Collider2D other)
	{
		if(other.tag.CompareTo("Enemy") == 0||other.tag.CompareTo("Enemy2") == 0)
		{
			fanghuzhao_Life--;
		}
        if (other.tag.CompareTo("Enemy_Rocket") == 0)
        {
            enemy2_Rocket enemy2 = other.GetComponent<enemy2_Rocket>();
            fanghuzhao_Life -= enemy2.m_Power;
            Destroy(enemy2.gameObject);
        }
	}
}
